<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<div class="resume-inf">
    <table>
        <tr>
            <!-- 简历头像 -->
            <td rowspan="5"> <a href="###" id="test4" class="layui-icon"><img id="imgavatar" src="http://localhost/hire-front-end/imgs/${resume.resume.resumeAvatar}" alt=""> <a href="###" id="test3" class="layui-icon"></td>
        </tr>
        <tr>
            <td>
                <%--                <c:if test="${!empty resume.resume.name}">--%>
                <div class="layui-inline">
                    <label class="layui-form-label">姓&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="name" placeholder="请输入姓名"
                               value="${resume.resume.name}">
                    </div>
                </div>
                <%--                </c:if>--%>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">性&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp别</label>
                    <div class="layui-input-block" id="sex">
                        <input type="radio" value="男" name="sex"
                               <c:if test="${resume.resume.sex=='男'}">checked</c:if>
                               style="height:20px;width:20px;cursor: pointer">&nbsp&nbsp男&nbsp&nbsp
                        <input type="radio" value="女" name="sex"
                               <c:if test="${resume.resume.sex=='女'}">checked</c:if>
                               style="height:20px;width:20px;cursor: pointer">&nbsp&nbsp女&nbsp&nbsp
                    </div>
                </div>
            </td>
        </tr>

        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">当前身份</label>
                    <div class="layui-input-block">
                        <select name="resIdentity" lay-verify="required" id="resIdentity">
                            <option value="无">请选择</option>
                            <option value="学生" <c:if test="${resume.resume.resIdentity=='学生'}">selected</c:if>>学生
                            </option>
                            <option value="职场人" <c:if test="${resume.resume.resIdentity=='职场人'}">selected</c:if>>职场人
                            </option>
                        </select>
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">求职状态</label>
                    <div class="layui-input-block">
                        <select name="resState" lay-verify="required" id="resState">
                            <option value="待业" <c:if test="${resume.resume.resState=='待业'}">selected</c:if>>待业</option>
                            <option value="在岗" <c:if test="${resume.resume.resState=='在岗'}">selected</c:if>>在岗</option>
                            <option value="失业" <c:if test="${resume.resume.resState=='失业'}">selected</c:if>>失业</option>

                        </select>
                    </div>
                </div>
            </td>
        </tr>
        <tr>

            <td>
                <div class="layui-inline">
                    <label class="layui-form-label">出生年月</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="birth" placeholder="yyyy-MM-dd"
                               value="<fmt:formatDate value="${resume.resume.birthday}" pattern="yyyy-MM-dd"/>">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-inline">
                    <label class="layui-form-label">所在城市</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="area" placeholder="请输入所在城市"
                               value="${resume.resume.area}">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-inline">
                    <label class="layui-form-label">电话号码</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="phone" placeholder="请输入电话号码"
                               value="${resume.resume.phone}">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-inline">
                    <label class="layui-form-label">常用邮箱</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="email" placeholder="请输入常用邮箱"
                               value="${resume.resume.email}">
                    </div>
                </div>
            </td>

        </tr>

    </table>

    <button class="button_save" id="button_basic_save">保存并更新</button>
    <button class="button_cancel" id="button_basic_cancel">取消</button>
</div>
<script>


    $("#button_basic_save").click(function () {
        let resumeId = $("#resumeId").val();
        // console.log($("#basic_info"))
        // 在这里写更新的方法
        //姓名
        let name = $("#name").val();
        console.log(name);
        //性别
        let sex;
        $("#sex input:radio").each(function () {
            if (this.checked) {
                sex = $(this).val();
            }
        })
        console.log(sex);
        // 身份
        let resIdentity = $("#resIdentity option:selected").val();
        console.log(resIdentity);
        // 求职状态
        let resState = $("#resState option:selected").val();
        console.log(resState);
        // 出生年月
        let birthday = $("#birth").val();
        console.log(birthday);
        //所在城市
        let area = $("#area").val();
        console.log(area);
        //电话号码
        let phone = $("#phone").val();
        console.log(phone);
        //常用邮箱
        let email = $("#email").val();
        console.log(email);
        let param = "id=" + resumeId + "&name=" + name + "&sex=" + sex + "&resIdentity=" + resIdentity +
            "&resState=" + resState + "&birthday=" + birthday + "&area=" + area + "&phone=" + phone + "&email=" + email;
        console.log(param);

        // 进行更新操作
        $.post('/hire/resume/basic/update', param, function (res) {
            if (res.code == '200') {
                $("#basic_info").load("/hire/resume/basic_info", {id: resumeId});
                $("#basic_edit").hide();
                $("#basic_info").show();
            } else {
                layer.msg(res.msg);
            }
        })


    })


    $("#button_basic_cancel").click(function () {
        let resumeId = $("#resumeId").val();
        // console.log($("#basic_info"))
        $("#basic_info").load("/hire/resume/basic_info", {id: resumeId});
        $("#basic_edit").hide();
        $("#basic_info").show();
    })


    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#birth'
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test4' //绑定元素
            ,url: '/hire/resume/upload' //上传接口
            ,done: function(res){
                alert("上传成功")
                document.getElementById("imgavatar").setAttribute("src","http://localhost/hire-front-end/imgs/"+res.data)
            }

        });
    });
</script>